package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.system.service.ISysDeptService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Rzs;
import com.ruoyi.system.service.IRzsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 入驻商管理Controller
 *
 * @author ruoyi
 * @date 2025-04-22
 */
@RestController
@RequestMapping("/system/rzs")
public class RzsController extends BaseController
{
    @Autowired
    private IRzsService rzsService;

    @Autowired
    private ISysDeptService sysDeptService;

    /**
     * 查询入驻商管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:rzs:list')")
    @GetMapping("/list")
    public TableDataInfo list(Rzs rzs)
    {
        startPage();
        List<Rzs> list = rzsService.selectRzsList(rzs);
        return getDataTable(list);
    }


    @PreAuthorize("@ss.hasPermi('system:rzs:list')")
    @GetMapping("/listOne")
    public TableDataInfo listOne(Rzs rzs)
    {
        List<Rzs> list = rzsService.selectRzsList(rzs);
        return getDataTable(list);
    }

    /**
     * 导出入驻商管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:rzs:export')")
    @Log(title = "入驻商管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Rzs rzs)
    {
        List<Rzs> list = rzsService.selectRzsList(rzs);
        ExcelUtil<Rzs> util = new ExcelUtil<Rzs>(Rzs.class);
        util.exportExcel(response, list, "入驻商管理数据");
    }

    /**
     * 获取入驻商管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rzs:query')")
    @GetMapping(value = "/{rzsId}")
    public AjaxResult getInfo(@PathVariable("rzsId") Long rzsId)
    {
        return success(rzsService.selectRzsByRzsId(rzsId));
    }

    /**
     * 新增入驻商管理
     */
    @PreAuthorize("@ss.hasPermi('system:rzs:add')")
    @Log(title = "入驻商管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Rzs rzs)
    {
        return toAjax(rzsService.insertRzs(rzs));
    }

    /**
     * 修改入驻商管理
     */
    @PreAuthorize("@ss.hasPermi('system:rzs:edit')")
    @Log(title = "入驻商管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Rzs rzs)
    {
        return toAjax(rzsService.updateRzs(rzs));
    }

    /**
     * 删除入驻商管理
     */
    @PreAuthorize("@ss.hasPermi('system:rzs:remove')")
    @Log(title = "入驻商管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rzsIds}")
    public AjaxResult remove(@PathVariable Long[] rzsIds)
    {
        SysDept sysDept = sysDeptService.selectOneLeaderIdOne(rzsIds);
        if(sysDept!=null){
            throw new RuntimeException("已有入驻商已经绑定团队,不可删除");
        }
        return toAjax(rzsService.deleteRzsByRzsIds(rzsIds));
    }
}
